package asteroids.model.programs.parsing.expressions;

import java.util.List;
import java.util.Map;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of expressions.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public abstract class Expression {
	public Expression(int line, int column){
		this.line=line;
		this.column=column;
	}

	@Basic
	public int getLine(){
		return line;
	}

	private int line;

	@Basic
	public int getColumn(){
		return column;
	}

	private int column;

	public abstract Type eval(Ship ship, Map<String, Type> globals);

	@Override
	public String toString(){
		return toString(null);
	}

	public String toString(Ship ship){
		if(eval(ship, null)!=null){
			return eval(ship, null).toString();
		}
		else{
			return "null";
		}
	}

	public boolean equals(Expression other, Ship ship){
		if((eval(ship,null)==null && other.eval(ship,null)!=null)){
			return false;
		}
		return ((eval(ship,null)==null && other.eval(ship,null)==null) || eval(ship, null).equals(other.eval(ship, null)));
	}

	public abstract List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals);
}
